package com.zmj.framework.handler.exception;

import com.zmj.framework.exception.server.ServerException;
import com.zmj.framework.response.ResponseCode;
import com.zmj.framework.response.Result;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ServerExceptionControllerAdvice {

    @ExceptionHandler(ServerException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Result<Void> handleForbiddenDataException(ServerException ex) {
        return ExceptionMapperUtil.buildBody(ex,ResponseCode.INTERNAL_SERVER_ERROR);
    }

}
